<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <div style="float: right;margin-right: 17px;margin-top: 16px;">
        <el-button type="primary" size="mini" @click="addMaterialCollection()" v-if="stateControlBtn!='0'">新增材料收集</el-button>
      </div>
      <div class="card-body">
        <avue-crud :data="levyResultData"
                   :option="tableoption"
                   :page="page"
                   :table-loading="tableLoading"
                   @on-load="getResultList"
                   @size-change="sizeChange"
                   @current-change="currentChange"
                   class="menu-min-height">
          <template slot-scope="scope" slot="menu">
            <div class="menu-title" @click.stop="collectionFeedback(scope.row,scope.index)"
                 v-if="scope.row.state!='1'&&scope.row.state!='0'&&scope.row.state!='2'">
              <i class="iconfont iconview icon-primary"></i>
              <p class="menu-title-text">查看反馈</p>
            </div>
            <div class="menu-title" @click.stop="urgentCollection(scope.row,scope.index)" v-if="scope.row.state=='1'">
              <i class="iconfont iconalter icon-warning"></i>
              <p class="menu-title-text">催办</p>
            </div>
          </template>
        </avue-crud>
      </div>
    </div>
  </basic-container>
</template>

<script>
  import {getLevyFeedbackAllList, levyDelete} from "@/api/subject";
  import {getmaterialCollectionAll,urgentCollection} from "@/api/fileTask";
  import {typeMap} from "@/views/fileTask/const";
  export default {
    name: "materialCollection",
    created() {
      if(this.$route.query.stateControlBtn==undefined){
        this.stateControlBtn ='1';
      }else {
        this.stateControlBtn = this.$route.query.stateControlBtn
      }
      this.headerData.title = typeMap[this.$route.query.type] + '-材料收集'
    },
    data() {
      return {
        headerData: {
          title: '课题研究-材料收集'
        },
        stateControlBtn:'',
        levyResultData: [],
        dialogVisible: false,
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableoption: {
          page: true,
          menuWidth: 180,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          keyId: "id",
          column: [
            {
              label: "材料收集名称",
              prop: "title",
              cell: true
            },
            {
              label: "反馈部门",
              width: 170,
              prop: "deptName",
              cell: true
            },
            {
              label: "截止时间",
              width: 110,
              prop: "endDate",
              cell: true
            },
            {
              label: "状态",
              width: 80,
              prop: "state",
              cell: true,
              formatter: function (row, value, label, column) {
                switch (row.state) {
                  case '0':
                    return "<font color='red'>" + "催办" + "</font>";
                  case '1':
                    return "<font color='red'>" + "待反馈" + "</font>";
                  case '2':
                    return "<font color='#DCA450'>" + "补充" + "</font>";
                  case '3':
                    return "<font color='#7EBE50'>" + "已反馈" + "</font>";
                }
              }
            },
          ]
        },
        tableLoading: false,
      }
    },
    methods: {
      currentChange(currentPage) {
        var page = this.page;
        page.currentPage = currentPage;
        this.getResultList(page);
      },
      sizeChange(pageSize) {
        var page = this.page;
        page.pageSize = pageSize;
        this.getResultList(page);
      },
      getResultList(page) {
        getmaterialCollectionAll(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          relateId: this.$route.params.id,
          type: this.$route.query.type
        })).then(response => {
          this.levyResultData = response.data.data.records;
          this.page.total = response.data.data.total;
        })
      },
      // 发起课题征集跳转
      addMaterialCollection() {
        let src = `/addMaterialCollection/detail/${this.$route.params.id}`;
        this.$router.push({
          path: src,
          query: {
            subjectTitle: this.$route.query.subjectTitle,
            type:this.$route.query.type
          }
        })
      },
      // 查看反馈
      collectionFeedback(row) {
        let src = `/collectionFeedback/detail/${row.fileTaskId}`;
        this.$router.push({
          path: src,
          query: {
            subjectId: row.subjectId,
            singleOrNot: '0',
            state: row.state,
            type:this.$route.query.type
          }
        })
      },
      urgentCollection(row) {
        this.$confirm("确定向相应部门发起催办吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          urgentCollection(row.fileTaskId).then(response => {
            if (response.data.code == 0) {
              this.$notify({
                title: '成功',
                message: '催办成功',
                type: 'success',
                duration: 2000
              });
              this.$router.go(0);
            }
          })
        })
      },
    }
  }
</script>

<style lang="scss" scoped>

</style>
